package poker;

import java.util.LinkedList;

/**
 * This class implements a player.
 *
 * @author Antti M. Harittu
 */
public class Player {
    
    /** Name */
    private String n;
    
    /** Hand */
    private LinkedList<Card> h;
    
    /** Wins */
    private int w;
    
    /**
     * This method creates a player that has the name n and an emply hand.
     * 
     * @param n 
     */
    public Player(String n) {
        this.n = n;
        this.h = new LinkedList<Card>();
    } // end Player

    /**
     * This method draws five cards from the deck and places them into the hand.
     */
    public void setHand() {
        this.h = new LinkedList<Card>();
        for (int i = 0; i < 5; i++) {
            this.h.add(Poker.draw());
        }
    } // setHand

    /**
     * The method draws one card from the deck and places it into the index i of
     * the hand. i >= 0 && i <= 5.
     * 
     * @param i 
     */
    public void setCard(int i) {
        this.h.remove(i);
        this.h.add(i, Poker.draw());
    } // setCard

    /** This method increases the value of w by one. */
    public void setWin() { this.w++; }
    
    /**
     * This method returns n.
     * 
     * @return 
     */
    public String getN() { return this.n; }

    /**
     * The method returns the rank of the card of index i in the hand.
     * i >= 0 && i <= 5.
     * 
     * @param i
     * @return 
     */
    public Card getCard(int i) { return h.get(i); }

    /**
     * This method returns the whole hand.
     * 
     * @return 
     */
    public LinkedList<Card> getHand() { return this.h; }

    /**
     * This method returns w.
     * 
     * @return 
     */
    public int getW() { return this.w; }

    /**
     * This method prints the current hand through System.out.
     */
    public void printAction() {
        for (int i = 0; i < 5; i++) {
            System.out.print(this.h.get(i) + "\t");
        }
        System.out.println();
    } // printAction
} // end class Player